package com.industrial.governance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.governance.domain.DgQualityRuleManagement;
import com.industrial.governance.service.IDgQualityRuleManagementService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 质量规则管理Controller
 *
 * @author SangGuangCan
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/rulemanagement")
public class DgQualityRuleManagementController extends BaseController
{
    @Autowired
    private IDgQualityRuleManagementService dgQualityRuleManagementService;

    /**
     * 查询质量规则管理列表
     */
    @RequiresPermissions("rulemanagement:rulemanagement:list")
    @GetMapping("/list")
    public TableDataInfo list(DgQualityRuleManagement dgQualityRuleManagement)
    {
        startPage();
        List<DgQualityRuleManagement> list = dgQualityRuleManagementService.selectDgQualityRuleManagementList(dgQualityRuleManagement);
        return getDataTable(list);
    }

    /**
     * 导出质量规则管理列表
     */
    @RequiresPermissions("rulemanagement:rulemanagement:export")
    @Log(title = "质量规则管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DgQualityRuleManagement dgQualityRuleManagement)
    {
        List<DgQualityRuleManagement> list = dgQualityRuleManagementService.selectDgQualityRuleManagementList(dgQualityRuleManagement);
        ExcelUtil<DgQualityRuleManagement> util = new ExcelUtil<DgQualityRuleManagement>(DgQualityRuleManagement.class);
        util.exportExcel(response, list, "质量规则管理数据");
    }

    /**
     * 获取质量规则管理详细信息
     */
    @RequiresPermissions("rulemanagement:rulemanagement:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(dgQualityRuleManagementService.selectDgQualityRuleManagementByBaseId(baseId));
    }

    /**
     * 新增质量规则管理
     */
    @RequiresPermissions("rulemanagement:rulemanagement:add")
    @Log(title = "质量规则管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DgQualityRuleManagement dgQualityRuleManagement)
    {
        return toAjax(dgQualityRuleManagementService.insertDgQualityRuleManagement(dgQualityRuleManagement));
    }

    /**
     * 修改质量规则管理
     */
    @RequiresPermissions("rulemanagement:rulemanagement:edit")
    @Log(title = "质量规则管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DgQualityRuleManagement dgQualityRuleManagement)
    {
        return toAjax(dgQualityRuleManagementService.updateDgQualityRuleManagement(dgQualityRuleManagement));
    }

    /**
     * 删除质量规则管理
     */
    @RequiresPermissions("rulemanagement:rulemanagement:remove")
    @Log(title = "质量规则管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(dgQualityRuleManagementService.deleteDgQualityRuleManagementByBaseIds(baseIds));
    }
}
